<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Main extends DR_Controller {

	function __Construct()
	{
		parent::__Construct();
	}
	
	public function index()
	{	
		$data = array("");
		if($this->is_admin())
		{
			$this->set_view("admin/header","admin/index",$data);	
		}
		else
		{
			redirect("admin/main/login");
		}
	}
	
	public function do_login()
	{
		$user = $this->read_post("user");
		$pwd = $this->read_post("password");
		
		$newdata = array(
						 "id_role"=>1,
						 "username"=>$user
						);
		
		$this->session->set_userdata($newdata);		
		redirect("admin/main/index");
	}
	
	public function login()
	{
		$data = array();
		$data["action"] = site_url("admin/main/do_login");
		$this->load->view("admin/login",$data);
	}
	
	function logout($nextpage=null)
	{
		$newdata = array(
						   'id_role' => 0,
						   'username'  => "",
						   'logged_in' => FALSE
					   );

		$this->session->set_userdata($newdata);			
		
		if($nextpage==null)
		{
			redirect("main/index/0",null);
		}
		else
		{
			$nextpage = str_replace("~","/",$nextpage);
			redirect($nextpage,null);
		}
	}	
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */